{
  "properties" : { },
  "id" : "6fb938b89d8c46fda0eb7bcac4a37788",
  "script" : null,
  "groupId" : "e6cd7933a0e746b8b4af97af80c9c45c",
  "name" : "保存",
  "createTime" : 1728702394494,
  "updateTime" : 1728373337761,
  "lock" : null,
  "createBy" : null,
  "updateBy" : null,
  "path" : "/",
  "method" : "POST",
  "parameters" : [ ],
  "options" : [ ],
  "requestBody" : "{\r\n    \"tn\":\"tb_res_staff\",\r\n    \"data\":{\r\n        \"tn\":\"\",\r\n        \"id\":\"\"\r\n    }\r\n}",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"msg\": \"success\",\n    \"data\": [\n        {\n            \"dtype\": \"varchar\",\n            \"mlength\": 36,\n            \"cname\": \"id\",\n            \"ccomment\": \"ID\"\n        },\n        {\n            \"dtype\": \"varchar\",\n            \"mlength\": 36,\n            \"cname\": \"name\",\n            \"ccomment\": \"姓名\"\n        },\n        {\n            \"dtype\": \"varchar\",\n            \"mlength\": 36,\n            \"cname\": \"gender\",\n            \"ccomment\": \"性别\"\n        },\n        {\n            \"dtype\": \"varchar\",\n            \"mlength\": 36,\n            \"cname\": \"birth_age\",\n            \"ccomment\": \"年龄\"\n        },\n        {\n            \"dtype\": \"date\",\n            \"mlength\": null,\n            \"cname\": \"birthday\",\n            \"ccomment\": \"出生年月\"\n        },\n        {\n            \"dtype\": \"varchar\",\n            \"mlength\": 36,\n            \"cname\": \"post\",\n            \"ccomment\": \"职务/职称\"\n        },\n        {\n            \"dtype\": \"varchar\",\n            \"mlength\": 36,\n            \"cname\": \"education\",\n            \"ccomment\": \"文化程度\"\n        },\n        {\n            \"dtype\": \"varchar\",\n            \"mlength\": 100,\n            \"cname\": \"graduate_institutions\",\n            \"ccomment\": \"毕业院校\"\n        },\n        {\n            \"dtype\": \"varchar\",\n            \"mlength\": 100,\n            \"cname\": \"major\",\n            \"ccomment\": \"所学专业\"\n        },\n        {\n            \"dtype\": \"int\",\n            \"mlength\": null,\n            \"cname\": \"is_empower_sign\",\n            \"ccomment\": \"是否授权签字人：0：否；1：是\"\n        },\n        {\n            \"dtype\": \"int\",\n            \"mlength\": null,\n            \"cname\": \"is_special\",\n            \"ccomment\": \"是否特定岗位：\\r\\n            0：否；\\r\\n            1：是。\"\n        },\n        {\n            \"dtype\": \"varchar\",\n            \"mlength\": 100,\n            \"cname\": \"email\",\n            \"ccomment\": \"邮箱\"\n        },\n        {\n            \"dtype\": \"varchar\",\n            \"mlength\": 30,\n            \"cname\": \"phone\",\n            \"ccomment\": \"联系电话\"\n        },\n        {\n            \"dtype\": \"text\",\n            \"mlength\": 65535,\n            \"cname\": \"avatar\",\n            \"ccomment\": \"头像图片\"\n        },\n        {\n            \"dtype\": \"text\",\n            \"mlength\": 65535,\n            \"cname\": \"signature_picture\",\n            \"ccomment\": \"签名手写图片存储地址\"\n        },\n        {\n            \"dtype\": \"mediumtext\",\n            \"mlength\": 16777215,\n            \"cname\": \"signature_pic\",\n            \"ccomment\": \"签名手写图片\"\n        },\n        {\n            \"dtype\": \"varchar\",\n            \"mlength\": 36,\n            \"cname\": \"password_level\",\n            \"ccomment\": \"密码强度\"\n        },\n        {\n            \"dtype\": \"varchar\",\n            \"mlength\": 20,\n            \"cname\": \"license_number\",\n            \"ccomment\": \"证件号\"\n        },\n        {\n            \"dtype\": \"varchar\",\n            \"mlength\": 10,\n            \"cname\": \"license_type\",\n            \"ccomment\": \"证件类型：Other-其他，IDCard-身份证号码Passport-中国护照，HMPass-港澳居民来往内地通行证，MTP-台胞证,默认为IDCard\"\n        },\n        {\n            \"dtype\": \"varchar\",\n            \"mlength\": 1000,\n            \"cname\": \"remark\",\n            \"ccomment\": \"备注\"\n        },\n        {\n            \"dtype\": \"varchar\",\n            \"mlength\": 36,\n            \"cname\": \"create_by\",\n            \"ccomment\": \"创建人\"\n        },\n        {\n            \"dtype\": \"datetime\",\n            \"mlength\": null,\n            \"cname\": \"create_time\",\n            \"ccomment\": \"创建时间\"\n        },\n        {\n            \"dtype\": \"varchar\",\n            \"mlength\": 36,\n            \"cname\": \"update_by\",\n            \"ccomment\": \"更新人\"\n        },\n        {\n            \"dtype\": \"datetime\",\n            \"mlength\": null,\n            \"cname\": \"update_time\",\n            \"ccomment\": \"修改时间\"\n        }\n    ],\n    \"status\": 0\n}",
  "description" : null,
  "requestBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : null,
    "defaultValue" : null,
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "type",
      "value" : "save",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "data",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "Object",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ {
        "name" : "id",
        "value" : "",
        "description" : "",
        "required" : false,
        "dataType" : "String",
        "type" : null,
        "defaultValue" : null,
        "validateType" : "",
        "error" : "",
        "expression" : "",
        "children" : [ ]
      }, {
        "name" : "name",
        "value" : "zs",
        "description" : "",
        "required" : false,
        "dataType" : "String",
        "type" : null,
        "defaultValue" : null,
        "validateType" : "",
        "error" : "",
        "expression" : "",
        "children" : [ ]
      } ]
    } ]
  },
  "responseBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : null,
    "defaultValue" : null,
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "msg",
      "value" : "系统内部出现错误：期待 'an identifier','and','or', 获得 ')'",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "data",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "Object",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "status",
      "value" : "1",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  }
}
================================
import log

var camelToUnderline = (str)=> {
    StringBuilder result = new StringBuilder();
    for (i in range(0,str.length()-1)) {
        char c = str.charAt(i);
        if (Character.isUpperCase(c) && i > 0) {
            result.append("_");
        }
        result.append(Character.toLowerCase(c));
    }
    return result.toString();
}
var tn = body.tn
var data = body.data
var cinfo = db.select("""
    SELECT DATA_TYPE dtype,CHARACTER_MAXIMUM_LENGTH mlength,COLUMN_NAME cname, 
        COLUMN_COMMENT ccomment,IS_NULLABLE isnull
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = database() AND TABLE_NAME = #{tn};
""")
// return cinfo
var tdata = {}
var id = data.id
if (!data.id){
    data.id = uuid()
}
for (key,value in data) {
    for (c in cinfo) {
        if (c.cname.equals(camelToUnderline(key))){
            log.info("isnull:{},value:{}",c.isnull,value)
            if ("NO".equals(c.isnull) && !value && c.cname!="id"){
                exit 1, c.ccomment+"不能为空";
            }
            if (c.dtype.equals("date")){
                
            }
            if (c.dtype.equals("datetime")){
                
            }
            if (c.dtype.equals("int")){
                
            }
            tdata[c.cname] = value
        }
    }
}
var r = db.table(tn).primary("id").save(tdata,true)
exit 0, "保存成功",tdata;